<?
	cria_variaveis($_POST,$_GET,$_FILES);
?>
<p class="titulo" align="center"><?php echo $msg->get("SOMA_MSG_02") ?></p>
<p class="subtitulo" align="center"><?php echo $msg->get("SOMA_MSG_03") ?></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=soma.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get("Material_Teorico") ?></a></li>
    <li><a href="index.php?inc=soma.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get("Exemplos_Prontos") ?></a></li>
    <li><a href="index.php?inc=soma.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get("Entrada_Teclado") ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
if (!isset($Calcular))
{
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        require_once("./classes/upload.php");
        $uploads = new Upload();
        $uploads->Lista("matriz");
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
    { //leitura de dados via banco de dados - modulo de exemplos e exercicios
        include "exibe_prob_matriz_soma_xml.php";
	}
	else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") {
	   if ((strlen($rows)==0) | ($rows<0) | ($columns<0) | (strlen($columns)==0))  {
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=soma.php>";
		echo $msg->get("SOMA_MSG_04");
		echo "<input type=text size='2' maxlength='2' name=rows value=".($rows).">";
		echo "X";
		echo "<input type=text size='2' maxlength='2' name=columns value=".($columns).">";
		echo "<br><br>";
			echo "<input type=hidden name=executar value=sim>";
		echo "<input class=button type=submit name=Submit value=".$msg->get("G_MSG_02").">";
			
        echo "</form>"; 
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=soma.php>";
		echo "<input class=button type=submit name=Submit value=".$msg->get("G_MSG_03").">";
		echo "</form>";
	   }
       elseif (!checaNumerico($rows) || !checaNumerico($columns))
       {
?>
        <p><font color="red"><?php echo $msg->get("Apenas_Dados_Numericos") ?></font></p>
        <p><input type="button" value="<?php echo $msg->get("Voltar") ?>" onclick="history.back()" class="button"></p>
<?php
       }
       else  { 
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=soma.php>";
		//echo SOMA_MSG_04;
		echo "<input type=hidden name=rows value=".($rows).">";
		//echo "X";
		echo "<input type=hidden name=columns value=".($columns).">";
		echo "<br><br>";
		echo "<p align=left><font face=Arial>".$msg->get("SOMA_MSG_05")."</font>";
		echo "<nobr>";
		for ($i=0; $i<$rows; $i++) {
		   echo "<br><br>";
		   for ($j=0; $j<$columns; $j++) {
				echo "<input type=text name=A[".($i)."][".($j)."] maxlength=10 size=5 value=".($A[$i][$j]).">";
		   } //end forj
		} //end fori
		echo "</nobr>";
		echo "<p>";
		echo "<p align=left><font face=Arial>".$msg->get("SOMA_MSG_06")."</font>";
		echo "<nobr>";
		for ($i=0; $i<$rows; $i++) {
		   echo "<br><br>";
		   for ($j=0; $j<$columns; $j++) {
				echo "<input type=text name=B[".($i)."][".($j)."] maxlength=10 size=5 value=".($B[$i][$j]).">";
		   } //end forj
		} //end fori
		echo "</nobr>";
		echo "<p>";
		echo "<input class=button type=submit name=Calcular value=".$msg->get("G_MSG_04").">";
		echo "<br>";
		echo "</form>";
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=soma.php>";
		echo "<input class=button type=submit name=Submit value=".$msg->get("G_MSG_03").">";
		echo "</form>";
	   } //end if
	   echo "</body>";
	}
} else {
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
        verificaBib($xml_file);
    if (!checaNumerico($rows) || !checaNumerico($columns) || !checaNumerico($A) || !checaNumerico($B))
    {
?>
        <p><font color="red"><?php echo $msg->get("Apenas_Dados_Numericos") ?></font></p>
        <p><input type="button" value="<?php echo $msg->get("Voltar") ?>" onclick="history.back()" class="button"></p>
<?php
    }
    else
    {
        echo "<br>";
        echo $msg->get("SOMA_MSG_04");
        echo " $rows";
        echo "X";
        echo "$columns";
        echo "<br><br>";
        echo "<table border=\"0\">\n";
        for ($i = 0; $i < $rows+1; $i++)
        {
            echo "<tr>\n";
            for ($j = 0; $j < ($columns*3)+2; $j++)
            {
                if ($i == 0)
                {
                    if ($j == 0) echo "<td colspan=\"$columns\" align=\"center\">".$msg->get("SOMA_MSG_05")."</td>";
                    else if ($j == ($columns)+1) echo "<td colspan=\"$columns\" align=\"center\">".$msg->get("SOMA_MSG_06")."</td>";
                    else if ($j == ($columns*2)+2) echo "<td colspan=\"$columns\" align=\"center\">".$msg->get("SOMA_MSG_08")."</td>";
                        if ($j == 1 || $j == ($columns)+2) echo "<td>&nbsp;</td>";
                }
                else if ($j < $columns)
                {
                    echo "<td width=\"40\" align=\"center\">".$A[$i-1][$j]."</td>";
                }
                else if ($j > $columns && $j < $columns*2+1)
                {
                    echo "<td width=\"40\" align=\"center\">".$B[$i-1][$j-($columns+1)]."</td>";
                }
                else if ($j > $columns*2+1)
                {
                    echo "<td width=\"40\" align=\"center\">".($A[$i-1][$j-($columns*2+2)] + $B[$i-1][$j-($columns*2+2)])."</td>";
                }
                else
                    if ($i == 1)
                    {
                        if ($j == $columns) echo "<td rowspan=\"$rows\"><b>+</b></td>";
                        else echo "<td rowspan=\"$rows\"><b>=</b></td>";
                    }
            }
            echo "\n</tr>\n";
        }
        echo "</table>";
        if (isset($correcao) && $correcao=="sim") {
        echo "<br><br><b>".$msg->get("SOMA_MSG_07")."</b>";
        for ($i=0; $i<$rows; $i++) {
                echo "<br><br>";
                for ($j=0; $j<$columns; $j++) {
                    echo "<input type=text name=C1[".($i)."][".($j)."] maxlength=10 size=5 value=".($C1[$i][$j]).">";
                } //end forj
        } //end fori
        echo "<br>";
        } // end if
        echo "</form>";
        echo "<p>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
        {
            echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
            echo "<script language=\"javascript\" type=\"text/javascript\">\n";
            echo "function criarLinks(value) {\n";
            echo "document.exemplos.indice.value = value;\n";
            echo "document.exemplos.action = 'index.php?inc=soma.php&modo=exemplo'\n";
            echo "document.exemplos.submit();\n";
            echo "}\n";
            echo "</script>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\">";
            echo "<br><br>".$msg->get("Outros_Exemplos")."<br>";
            $objeto = new DomDocument();
            $objeto->load($xml_file);
            $filho = $objeto->getelementsbytagname("matrices");
            if ($filho->length > 0)
            {
                $temp = $filho->item(0)->getelementsbytagname("matrix");
                $j = 0;
                for($i = 0; $i < $temp->length; $i++) {
                    $conteudo = $temp->item($i)->getelementsbytagname("num_rows");
                    if ($conteudo->length == 1)
                    {
                        if ($j != 0) echo " | ";
                        if ($j == $indice) echo "<b>";
                        echo "<a href=\"javascript:criarLinks($j)\"><u>".($j+1)."</u></a>";
                        if ($j == $indice) echo "</b>";
                        $j++;
                    }
                }
            }
            echo "<br><br>";
        }
        echo "<form method=post enctype=multipart/form-data action=index.php?inc=soma.php>";
        echo "<input class=button type=submit name=Submit value=".$msg->get("G_MSG_03").">";
        echo "</form>";
    }
}
?>
</div>